package com.longtop.leaning.ui;

import java.util.Enumeration;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import com.longtop.leaning.data.AppData;
import com.longtop.leaning.data.UIData;
import com.longtop.leaning.entity.FlightData;

public class FltList extends List implements CommandListener{
	
	public FltList() {
		super("航班列表", Choice.IMPLICIT, new String[]{}, null);
		
		Enumeration e = AppData.flights.elements();
		FlightData flight = null;
		while(e.hasMoreElements()){
			flight = (FlightData)e.nextElement();
			super.append(flight.getFltno(), null);
		}
		
		super.addCommand(UIData.CMD_BACK);
		super.addCommand(UIData.CMD_OK);
		super.setCommandListener(this);
	}

	public void commandAction(Command c, Displayable d) {
		if(c == UIData.CMD_OK || c == List.SELECT_COMMAND){
			int index = ((List) d).getSelectedIndex();
			AppData.selectedIndex = index;
			UIData.display.setCurrent(new FltDetailLit());
		}
		if (c == UIData.CMD_BACK) {
			UIData.display.setCurrent(new MainForm());
		}
		
	}

}
